home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / devices and hardware / display manager / play video sample / playvideo.c next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  6.1 KB  |  134 lines

  1. /*
  2.     File:        PlayVideo.c
  3.  
  4.     Contains:    PlayVideo demonstrates the usage of the RequestVideo sample library
  5.                 to make Display Manager calls. With PlayVideo, you can explore the
  6.                 RequestVideo API by changing bit depth and screen resolution on
  7.                 multisync displays. The purpose of this code is to provide a sample of
  8.                 how developers can change the bit depth and timing of multisync
  9.                 displays under their own control. Game developers should love this!
  10.                 
  11.                 After requesting a desired bit depth, horizontal, and vertical resolutions
  12.                 using the RVRequestVideoSetting() call, we then make the RVSetVideoRequest()
  13.                 call to do the deed. At exit, we call RVSetVideoAsScreenPrefs() to force the
  14.                 world to look like that described in the screen prefs.
  15.         
  16.                 It is a good idea to reset the screen(s) to the original setting before exit
  17.                 since the call to RVSetVideoAsScreenPrefs() may not do the right thing under
  18.                 Display Manager 1.0 with certain video drivers.
  19.  
  20.     Written by: Eric Anderson    
  21.  
  22.     Copyright:    Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
  23.  
  24.                 You may incorporate this Apple sample source code into your program(s) without
  25.                 restriction. This Apple sample source code has been provided "AS IS" and the
  26.                 responsibility for its operation is yours. You are not permitted to redistribute
  27.                 this Apple sample source code as "Apple sample source code" after having made
  28.                 changes. If you're going to re-distribute the source, we require that you make
  29.                 it clear in the source that the code was descended from Apple sample source
  30.                 code, but that you've made changes.
  31.  
  32.     Change History (most recent first):
  33.                 7/15/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  34.                 1/28/97        ewa                Updated source for Metrowerks CodeWarrior 11
  35.                 5/31/95        ewa                Added RVGetCurrentVideoSetting and RVConfirmVideoRequest routines
  36.                                             to make it easy to revert back to where you came from and to give
  37.                                             the user a chance to confirm the new setting if the new mode was
  38.                                             valid (ie: the card supports it) but not safe (the monitor may not).
  39.                 
  40.  
  41. */
  42.  
  43. #include "RequestVideo.h"
  44. #include <Memory.h>
  45. #include <StdIO.h>
  46. #include <stdlib.h>
  47.  
  48. // routine defines
  49. unsigned long GetUserInputData (void);
  50.  
  51. // routine implementations
  52. void main(void)
  53. {
  54.     VideoRequestRec requestRec;
  55.     VideoRequestRec originalRec;
  56.     short        currentDepth;
  57.     short        currentHorizontal;
  58.     short        currentVertical;
  59.  
  60.     MaxApplZone();
  61.  
  62.     printf("Welcome to •Guess That Video•\n");
  63.     printf("\nIMPORTANT: WARNING WHEN CHANGING THE SCREEN RESOLUTION\n");
  64.     printf("IMPORTANT:       IN A MULTI-MONITOR ENVIRONMENT\n");
  65.     printf("IMPORTANT: Monitor gravitation (repositioning) is not suported under\n");
  66.     printf("IMPORTANT: Display Manager 1.0, and there is not currently any code\n");
  67.     printf("IMPORTANT: written in this sample library to provide even minimal\n");
  68.     printf("IMPORTANT: gravitate functionality.\n");
  69.     printf("IMPORTANT: Currently, changing the video settings on\n");
  70.     printf("IMPORTANT: multi-monitor systems under the Display Manager 1.0.\n");
  71.     printf("IMPORTANT: will result in only the bit depth being changed.\n");
  72.  
  73.     do
  74.     {
  75.         requestRec.screenDevice = nil;        // any screen
  76.         printf("\nRequested bit depth (999 to end the game):");
  77.         requestRec.reqBitDepth = GetUserInputData ();        // bit depth request
  78.         if (requestRec.reqBitDepth != 999)
  79.         {
  80.             // fill in the request record
  81.             printf("Requested horizontal resolution:");
  82.             requestRec.reqHorizontal = GetUserInputData ();;    // H request
  83.             printf("Requested vertical resolution:");
  84.             requestRec.reqVertical = GetUserInputData ();;        // V request
  85.             requestRec.displayMode = nil;                        // must init to nil
  86.             requestRec.depthMode = nil;                            // must init to nil
  87.             requestRec.requestFlags = 1<<kAllValidModesBit;                        // give me the HxV over bit depth, and only safe video modes
  88.  
  89.             // make the request and set it if we have one....
  90.             RVRequestVideoSetting(&requestRec);
  91.  
  92.             if (requestRec.screenDevice != nil)        // make sure we found a device...possible if there are no "safe" video modes
  93.             {
  94.                 // Get current setting
  95.                 originalRec.screenDevice = requestRec.screenDevice;        // this screen
  96.                 RVGetCurrentVideoSetting(&originalRec);
  97.                 
  98.                 // print out the current info
  99.                 currentDepth = (*(*(requestRec.screenDevice))->gdPMap)->pixelSize;
  100.                 currentHorizontal = abs ((*(*(requestRec.screenDevice))->gdPMap)->bounds.right - (*(*(requestRec.screenDevice))->gdPMap)->bounds.left);
  101.                 currentVertical = abs ((*(*(requestRec.screenDevice))->gdPMap)->bounds.bottom - (*(*(requestRec.screenDevice))->gdPMap)->bounds.top);
  102.                 printf ("\n");
  103.                 printf ("Info for GDevice at: %d\n", requestRec.screenDevice);
  104.                 printf ("Original depth:%d, horizontal:%d, vertical:%d\n", currentDepth, currentHorizontal, currentVertical);
  105.                 printf ("Requested depth:%d, horizontal:%d, vertical:%d\n", requestRec.reqBitDepth, requestRec.reqHorizontal, requestRec.reqVertical);
  106.                 printf ("Setting depth:%d, horizontal:%d, vertical:%d\n", requestRec.availBitDepth, requestRec.availHorizontal, requestRec.availVertical);
  107.             
  108.                 // Set/Confirm/Reset the request
  109.                 RVSetVideoRequest (&requestRec);
  110.                 if (noErr != RVConfirmVideoRequest (&requestRec))
  111.                     RVSetVideoRequest (&originalRec);
  112.                 
  113.                 // print out the new info            
  114.                 currentDepth = (*(*(requestRec.screenDevice))->gdPMap)->pixelSize;
  115.                 currentHorizontal = abs ((*(*(requestRec.screenDevice))->gdPMap)->bounds.right - (*(*(requestRec.screenDevice))->gdPMap)->bounds.left);
  116.                 currentVertical = abs ((*(*(requestRec.screenDevice))->gdPMap)->bounds.bottom - (*(*(requestRec.screenDevice))->gdPMap)->bounds.top);
  117.                 printf ("New depth:%d, horizontal:%d, vertical:%d\n", currentDepth, currentHorizontal, currentVertical);
  118.             }
  119.         }
  120.     } while (requestRec.reqBitDepth != 999);    // our clue to bail
  121.     printf("\nThank you for playing •Guess That Video•\n");
  122.  
  123.     // attempt to reset the world to screen prefs setting (may not do anything with old video drivers)
  124.     RVSetVideoAsScreenPrefs ();
  125. }
  126.  
  127. // Get user input of a number
  128. unsigned long GetUserInputData (void)
  129. {
  130.     long    tempLong = 0;                
  131.     do scanf ("%ld", &tempLong); while (tempLong == 0);        
  132.     return (tempLong);
  133. }
  134.